import Vue from 'vue'
import VueRouter from 'vue-router'
import { Notify } from 'vant';

Vue.use(VueRouter)

const routes = [{
    path: '/',
    name: 'Index',
    component: () => import('../views/Index.vue'),
    children: [{
        path: '/',
        name: 'Home',
        component: () => import('@/components/Home/Home.vue'),
    }, {
        path: '/BannerDetail',
        name: 'BannerDetail',
        component: () => import('@/components/Home/BannerDetail.vue'),
    }, {
        path: '/Record',
        name: 'Record',
        component: () => import('../views/Record'),
    }, {
        path: '/Practice',
        name: 'Practice',
        component: () => import('../views/Practice.vue'),
    }, {
        path: '/My',
        name: 'My',
        component: () => import('../views/My.vue'),
        // 路由守卫
        beforeEnter: (to, from, next) => {
            var adminToken = localStorage.getItem("adminToken")
            // console.log(adminToken);
            if (!adminToken) {
                Notify({ type: 'warning', message: '请先登录哦！' });
                next("/login")
                return false
            }
            next()
        },
    }]
}, {
    path: '/Login',
    name: 'Login',
    component: () => import('../views/Login.vue'),
}, {
    path: '/Smslogin',
    name: 'Smslogin',
    component: () => import('../views/Smslogin.vue'),
}, {
    path: '/MysetPass',
    name: 'MysetPass',
    component: () => import('../views/MysetPass.vue'),
}, {
    path: '/Custmoer',
    name: 'Custmoer',
    component: () => import('../views/Custmoer'),
}, {
    path: '/Detail',
    name: 'Detail',
    component: () => import('@/components/Detail.vue'),
}, {
    path: '/Search',
    name: 'Search',
    component: () => import('@/components/Search.vue'),
}, {
    path: '/Userinfo',
    name: 'Userinfo',
    component: () => import('@/components/Userinfo.vue'),
},]


const router = new VueRouter({
    routes
})

export default router
